package com.yqg.protection.netty.handler;

import com.yqg.protection.utils.DataSaver;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.annotation.Resource;

public abstract class AbstractProtocolHandler extends ChannelInboundHandlerAdapter {
    @Autowired
    protected DataSaver dataSaver;

    @Resource(name = "dataExecutor")
    protected ThreadPoolTaskExecutor executor;

    // 实现必要的 ChannelInboundHandler 方法
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        // 默认实现，子类可以覆盖
        super.channelRead(ctx, msg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        // 处理异常
        cause.printStackTrace();
        ctx.close();
    }
}
